package com.spa.interfaces.common;

import cn.dev33.satoken.annotation.SaIgnore;
import com.spa.application.query.SysDictQuery;
import com.spa.infrastructure.util.StringUtils;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.infrastructure.config.SysDictEnumConfig;
import com.spa.infrastructure.enums.dict.DictionaryManagement;
import com.spa.interfaces.BaseController;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class DictController extends BaseController {

    @PostMapping("/sysDictAllList")
    public ResponseMessage<List<DictionaryManagement>> sysDictAllList() {
        List<DictionaryManagement> dictList = SysDictEnumConfig.dictManageList;
        return responseHelper.success(dictList);
    }

    @PostMapping("/sysDictByType")
    @SaIgnore
    public ResponseMessage<DictionaryManagement> dictTypeList(@RequestBody SysDictQuery query) {
        List<DictionaryManagement> dictList = SysDictEnumConfig.dictManageList;
        if (StringUtils.isNotEmpty(query.getType())) {
            List<DictionaryManagement> result = new ArrayList<>();
            dictList.stream().forEach(a -> {
                if(a.getDictType().equals(query.getType())){
                    result.add(a);
                }
            });
            return responseHelper.success(result);
        }
        return responseHelper.success(dictList);
    }

}
